// 缓存UUID
const UUID_KEY = 'BLUETOOTH_UUID'
// 缓存蓝牙连接信息
const BLUETOOTH_CONNECTION_KEY = 'BLUETOOTH_CONNECTION_INFO'

// 获取缓存的UUID
export function getUuid() {
  return uni.getStorageSync(UUID_KEY)
}

// 设置UUID到缓存
export function setUuid(uuid) {
  return uni.setStorageSync(UUID_KEY, uuid)
}

// 移除缓存的UUID
export function removeUuid() {
  return uni.removeStorageSync(UUID_KEY)
}

// 获取缓存的蓝牙连接信息
export function getBluetoothConnection() {
  return uni.getStorageSync(BLUETOOTH_CONNECTION_KEY) || null
}

// 设置蓝牙连接信息到缓存
export function setBluetoothConnection(socket, device) {
  // 由于socket对象不能直接存储，我们只存储设备信息
  const connectionInfo = {
    device: {
      name: device.getName(),
      address: device.getAddress()
    }
  }
  return uni.setStorageSync(BLUETOOTH_CONNECTION_KEY, connectionInfo)
}

// 移除缓存的蓝牙连接信息
export function removeBluetoothConnection() {
  return uni.removeStorageSync(BLUETOOTH_CONNECTION_KEY)
}

// 默认UUID (SPP服务标准UUID)
export const DEFAULT_UUID = '00001101-0000-1000-8000-00805F9B34FB'